var express = require('express')
var router = express.Router()
const { postLogin } = require('../controller/user')
const { Success, Error } = require('../model/res')

/* GET users listing. */
router.post('/login', async (req, res, next) => {
    const { username, password } = req.body
    let data = await postLogin(username, password)
    // 参数错误
    if (data.username == null) {
        return res.json(new Error('登录失败'))
    }
    // 参数正确，设置session
    req.session.username = data.username
    req.session.realname = data.realname
    res.json(new Success(data))
})

module.exports = router
